﻿RolePositionList = Class.create();

RolePositionList.prototype = Object.extend(new Common(), {
    initialize: function () {
        this.initCommonProperty();
    },
    init: function () {
        //添加角色
        Event.observe($("role_btnAdd"), 'click', this.onClick_addRole.bind(this));

        //修改角色
        Event.observe($("role_btnUpdate"), 'click', this.onClick_updateRole.bind(this));

        //        //删除角色
        //        Event.observe($("btnDelete", 'click', this.onClick_deleteRole.bind(this)));

        this.cmnSplitterIns = new CmnSplitter();

        //实现可以自定义拖动div分区
        this.initSplitter();

        this.roleData = null;

        this.selectedRoleData = null;

        //获取权限List
        this.getRoleList();
    },
    //实现可以自定义拖动div分区
    initSplitter: function () {
        //自定义拖动div的高度
        this.cmnSplitterIns.height = 670;

        //定义拖动div上部分高度
        this.cmnSplitterIns.topPanel.initHeight = 50;

        //定义左侧宽度
        this.cmnSplitterIns.leftPanel.initWidth = 200;

        //显示上部分DIV
        this.cmnSplitterIns.hasTopPanel = true;

        //自定义拖动div的init处理
        this.cmnSplitterIns.init("MySplitter", "role_div", "positionListByRoleId", "btn_div");

        //自定义拖动div的实现
        this.cmnSplitterIns.create();
    },
    getRoleList: function () {
        CmnMessage.showProcessing();
        //发送Ajax
        this.sendAjaxByModel("/Master/GetRoleList", null, this.getRoleListCallback.bind(this));
    },
    getRoleListCallback: function (response) {
        var json = this.jsonParse(response);

        this.roleData = json;

        var strHTML = "";
        for (var i = 0; i < json.length; i++) {
            strHTML += "<div style='text-align:center;padding-top:10px;'><span rowNo='" + i + "' id=roleList_'" + json[i].role_id + "' style='cursor:pointer;'>" + json[i].role_name + "</span></div><br/>";
        }
        $j("#roleList").html("");
        $j("#roleList").append(strHTML);

        //设置焦点事件以及点击事件
        this.setRowEventOrColor();

        CmnMessage.hide();
    },
    //设置焦点事件以及点击事件
    setRowEventOrColor: function () {
        //点击节点时触发事件
        this.setRowClickEvent();

        //得到或失去焦点时触发事件
        this.setRowMouseMoveEvent();
    },
    //得到或失去焦点时触发事件
    setRowMouseMoveEvent: function () {
        //获取id类似于this.treeViewId + "_cmnTreeView_span_display_value_的值
        var spanMouse = "[id*=roleList_]";

        $j(spanMouse).unbind("mouseover");
        $j(spanMouse).unbind("mouseout");

        $j(spanMouse).mouseover(function () {
            $j(this).addClass("treeViewSelecting");
        });

        $j(spanMouse).mouseout(function () {
            $j(this).removeClass("treeViewSelecting");
        });
    },
    setRowClickEvent: function () {
        var roleInfo = this.roleData;

        var rolePosition = this;

        var spanMouse = "[id*=roleList_]";

        $j(spanMouse).unbind("click");

        $j(spanMouse).click(function () {
            $j(spanMouse).removeClass("treeViewSelectingExt");
            $j(this).addClass("treeViewSelectingExt");
            rolePosition.selectedRoleData = roleInfo[$j(this).attr("rowNo")];
        });
    },
    //添加角色信息
    onClick_addRole: function () {
        this.roleInputIns.show(null, this.getRoleList.bind(this));
    },
    onClick_updateRole: function () {
        //判断是否选中角色
        if (this.selectedRoleData == null) {
            CmnMessage.showMessage("请选择角色", MSG_TYPE_INFO);
            return;
        }
        //获取要修改的role_id

        var role_id = this.selectedRoleData["role_id"];
        //调用input画面
        this.roleInputIns.show(role_id, this.getRoleList.bind(this));
    },
    onClick_deleteRole: function () {

    }
});